package juc;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author liwuji
 * @date 2024/1/19
 * @desc
 **/
public class LockSupportDemo1 {
    public static void main(String[] args) throws InterruptedException {
        ReentrantLock reentrantLock = new ReentrantLock();
        Condition condition = reentrantLock.newCondition();
        Object o = new Object();
        new Thread(()->{
            reentrantLock.lock();
                System.out.println(Thread.currentThread().getName()+" come in");
                try {
                    condition.await();
                }catch (Exception e){
                    e.printStackTrace();
                }
            System.out.println(Thread.currentThread().getName()+"被唤醒");
                reentrantLock.unlock();
                
        },"t1").start();
        TimeUnit.SECONDS.sleep(1);
        new Thread(()->{
            reentrantLock.lock();
                try {
                    condition.signal();
                    System.out.println(Thread.currentThread().getName()+" 发出通知");
                    
                }catch (Exception e){
                    e.printStackTrace();
                }
            reentrantLock.unlock();
        },"t2").start();
    }
}
